package com.xinli.business.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xinli.common.annotation.Log;
import com.xinli.common.core.controller.BaseController;
import com.xinli.common.core.domain.AjaxResult;
import com.xinli.common.enums.BusinessType;
import com.xinli.business.domain.ConsultantTags;
import com.xinli.business.service.IConsultantTagsService;
import com.xinli.common.utils.poi.ExcelUtil;

/**
 * 标签Controller
 *
 * @author ruoyi
 * @date 2025-03-24
 */
@RestController
@RequestMapping("/business/tags")
public class ConsultantTagsController extends BaseController
{
    @Autowired
    private IConsultantTagsService consultantTagsService;

    /**
     * 查询标签列表
     */
    @GetMapping("/list")
    public AjaxResult list(ConsultantTags consultantTags)
    {
        List<ConsultantTags> list = consultantTagsService.selectConsultantTagsList(consultantTags);
        return AjaxResult.success(list);
    }

    /**
     * 导出标签列表
     */
    @Log(title = "标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConsultantTags consultantTags)
    {
        List<ConsultantTags> list = consultantTagsService.selectConsultantTagsList(consultantTags);
        ExcelUtil<ConsultantTags> util = new ExcelUtil<ConsultantTags>(ConsultantTags.class);
        util.exportExcel(response, list, "标签数据");
    }

    /**
     * 获取标签详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(consultantTagsService.selectConsultantTagsById(id));
    }

    /**
     * 新增标签
     */
    @Log(title = "标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConsultantTags consultantTags)
    {
        if("0".equals(consultantTags.getParentId())){
            consultantTags.setLevel(1);
        }else{
            consultantTags.setLevel(2);
        }
        return toAjax(consultantTagsService.insertConsultantTags(consultantTags));
    }

    /**
     * 修改标签
     */
    @Log(title = "标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConsultantTags consultantTags)
    {
        return toAjax(consultantTagsService.updateConsultantTags(consultantTags));
    }

    /**
     * 删除标签
     */
    @Log(title = "标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(consultantTagsService.removeByIds(Arrays.asList(ids)));
    }
}
